package city.spring.modules.oldman.service.impl;

import city.spring.modules.oldman.entity.GooutRegisterEntity;
import city.spring.modules.oldman.repository.GooutRegisterRepository;
import city.spring.modules.oldman.service.GooutRegisterService;
import city.spring.modules.oldman.vo.GooutRegisterVO;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Service：外出登记
 *
 * @author 侯坤林
 * @date 2020-06-17 21:45:59
 */
@CacheConfig(cacheNames = {GooutRegisterServiceImpl.CACHE_NAME})
@Transactional(rollbackFor = Throwable.class)
@Service
public class GooutRegisterServiceImpl extends ServiceImpl<GooutRegisterRepository, GooutRegisterEntity> implements GooutRegisterService {

    @Override
    public void saveGooutRegister(GooutRegisterEntity entity) {
        if (!save(entity)) {
            throw new RuntimeException("保存信息失败");
        }
    }

    @Override
    public void updateGooutRegister(GooutRegisterEntity entity) {
        // 使用 updateById(entity); 修改数据时，将会修改 entity 对象中所有非null数据，如果某个字段为null，将会忽略该字段的修改
        boolean update = updateById(entity);
        if (!update) {
            throw new RuntimeException("修改信息失败");
        }
    }

    @Override
    public void deleteGooutRegister(String primaryKey) {
        removeById(primaryKey);
    }

    @Override
    public void deleteGooutRegister(List<String> primaryKeys) {
        removeByIds(primaryKeys);
    }

    @Override
    public IPage<GooutRegisterVO> listPage(Page<? extends GooutRegisterEntity> page, Wrapper<? extends GooutRegisterEntity> wrapper) {
        return baseMapper.listPage(page, wrapper);
    }
}